package com.hxl.demo.tools;

import com.hxl.demo.tools.enums.ResultCodeEnum;

import java.util.HashMap;
import java.util.Map;

public class Result {
    private Boolean success;
    private Integer code;
    private String message;

    private Map<String, Object> data = new HashMap<>();
    private Result(){}

    //自定义成功
    public static Result ok() {
        Result result = new Result();
        result.setSuccess(ResultCodeEnum.SUCCESS.getSuccess());
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        return result;
    }
    //通用失败
    public static Result fail() {
        Result result = new Result();
        result.setSuccess(ResultCodeEnum.FAIL.getSuccess());
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(ResultCodeEnum.FAIL.getMessage());
        return result;
    }
    //设置返回
    public static Result setResult(ResultCodeEnum result) {
        Result re = new Result();
        re.setSuccess(result.getSuccess());
        re.setCode(result.getCode());
        re.setMessage(result.getMessage());
        return re;
    }
    //设置自定义返回数据
    public Result data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }
    public Result data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }
    //自定义返回code
    public Result code(Integer code) {
        this.setCode(code);
        return this;
    }
    //自定义返回message
    public Result message(String message) {
        this.setMessage(message);
        return this;
    }
    //自定义返回结果
    public Result success(Boolean success) {
        this.setSuccess(success);
        return this;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }
}
